<!DOCTYPE html>
<html>
<head>
    {include file='public/meta'/}

    <style>
        thead tr th {
            text-align: center;
        }

        tbody tr td {
            text-align: center;
        }
    </style>
</head>
<body>
{include file='public/header'/}
<!------------------导航-------------------------->
<section id="content">
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <div class="page-heading mgl15 mgr15">
            <ul class="breadcrumb">
                <li>当前位置是&nbsp;:</li>
                <li>&nbsp;微信卡券</li>
                <li class="active" style="color: #02b87f;">卡券已领取列表</li>
            </ul>
        </div>
        <div class="panel panel-search panel-default mgl15 mgr15">
            <div class="panel-heading">
                <h3 class="panel-title">
                    筛选分类
                </h3>
            </div>
            <div class="panel-body">
                <form action="" method="get" class="form-horizontal table-search form-search" role="form" id="machform">
                    <div class="col-sm-6 col-md-6 col-lg-4 ">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">卡券code：</label>
                            <div class="col-sm-9">
                                <!--oninput="getDatas(this.value)" onkeydown="searchkeydown(event,'merchant')"-->
                                <input type="text" class="form-control"autocomplete="off" disableautocomplete id="code" placeholder="请输入" value="{$p_data['code']}" name="code">
                                <div class="searchlist hide">
                                    <ul>

                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6 col-md-6 col-lg-4 ">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">状态：</label>
                            <div class="col-sm-9">
                                <select name="statu" class="form-control">
                                    <option value="">请选择</option>
                                    <option value="2" {if condition="$p_data['statu'] eq '2' "}selected{/if}>已核销</option>
                                    <option value="0" {if condition="$p_data['statu'] eq '0' "}selected{/if}>未核销</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="panel-footer">
                <a href="javascript:;" class="btn btn-primary" onclick="searchform()">查找</a>
                <a href="javascript:;" class="btn btn-default" onclick="clearform()">清空</a>
            </div>
        </div>
        <div class="panel mgl15 mgr15">

            <div class="panel-heading addCharts" style="background:#ededed;">领取记录列表</div>
            <div class="panel-body">
                <table class="table table-bordered" data-toolbar="#toolbar">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>卡券名称</th>
                        <th>卡券CODE</th>
                        <th>领取人</th>
                        <th>领取时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="list" id="vo"}
                    <tr>
                        <td>{$vo.id}</td>
                        <td>{:getcardgel($vo.card_id,0)}</td>
                        <td>{$vo.code}</td>
                        <td title="{$vo.openid}">{:get_user_nickname($vo.openid)}</td>
                        <td>{$vo.create_time}</td>
                        <td>
                            {eq name="vo.have" value="1"}
                                {eq name="vo.statu" value="2"}
                                    已核销
                                {else/}
                                    {eq name="vo.statu" value="3"}
                                        不可用
                                    {else/}
                                            {eq name=":filtercardterm($vo['card_id'],$vo['code'])" value="true"}
                                                未核销
                                            {else/}
                                                已过期
                                            {/eq}
                                    {/eq}
                                {/eq}
                            {else/}
                                已删除
                            {/eq}
                        </td>

                        <td class="chakan">
                            {eq name="vo.statu" value="2"}
                            已核销
                            {else/}
                            {eq name="vo.have" value="1"}
                                <a class="btn-link" data-toggle="modal" data-target="#myModal" data-id="{$vo.id}">核销</a>
                            {else/}
                            已删除
                            {/eq}
                            {/eq}
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
            </table>
                {$list->render()}
            </div>
        </div>
        {include file='public/footer'/}
    </div>
</section>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">核销卡券</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="hexiao">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">门店：</label>
                        <div class="col-sm-10">
                            <input type="hidden" name="id" id="card-id" >
                            <select name="mid" id="he-md" class="form-control" required="required">
                                <option value="">选择门店</option>
                                {volist  name="mach" id="md"}
                                <option value="{$md.id}">{$md.merchant}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">核销员：</label>
                        <div class="col-sm-10">
                            <input type="text" name="nickname" id="nickname" readonly="readonly"  required="required" class="form-control" value="{$user.nickname}">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="hxsure">确认</button>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__STATIC_URL__/static/js/commen.js" type="text/javascript" charset="utf-8"></script>
<script src="__STATIC_URL__/static/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<script>
    $(function(){
        $("#myModal").on('show.bs.modal',function () {
            var id = $(event.target).attr("data-id");
            var qx = "{:checkPath('cards/cardconsumes')}";
            if(qx==0){
                layer.alert("没有核销权限");
                return false;
            }
            $("#card-id").val(id);
        });
        $("#myModal").on('hide.bs.modal',function () {
            $("#card-id").val("");
            $("#he-md").val("");
        });
        $("#hxsure").click(function(){
            var mid = $("#he-md").val();
            var nickname = $("#nickname").val();
            if(mid==""){
                layer.alert("请选择门店",{icon:7});
                return false;
            }
            if(nickname==""){
                layer.alert("核销员不能为空",{icon:7});
                return false;
            }
            $.ajax({
                url:"{:url('cards/cardconsumes')}",
                type:"post",
                data:$("#hexiao").serialize(),
                success:function(data){
                    console.log(data);
                    if(data.code==0){
                        layer.msg("核销成功",{icon:1,time:1000});
                        setTimeout("window.location.reload()",1000)
                        return false;
                    }else{
                        layer.alert(data.message,{icon:7});
                        return false;
                    }
                }
            })
        })
    })
</script>

</html>
